﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LEARNREN.COM.BLL;
using LEARNREN.COM.Entity;
using LEARNREN.COM.TOOL;

namespace LEARNREN.COM.UI.LabelProviders
{
    /// <summary>
    /// 用户自定义标签
    /// </summary>
    class CSLabel : AbstractLabelProvider
    {
        public CSLabel(string label)
            : base(label)
        {

        }

        public override string GetHtml()
        {
            try
            {
                string[] paras = LabelProviderHelper.GetProperties(this.LabelString);
                if (paras.Length < 1)
                {
                    return this.LabelString;
                }
                long id = 0;
                if (!long.TryParse(paras[0], out id))
                {
                    return this.LabelString;
                }

                CustomSection cs = this.GroupLogicFactory.CustomSectionLogic.GetById(id);
                if (cs == null)
                {
                    return this.LabelString;
                }

                int showtype = 0;
                if (paras.Length > 1)
                {
                    int.TryParse(paras[1], out showtype);
                }

                if (showtype < 0 || showtype > 2)
                {
                    return this.LabelString;
                }

                StringBuilder sb = null;
                switch (showtype)
                {
                    case 0:
                        sb = new StringBuilder();
                        sb.AppendLine("<div class=\"sc\">");
                        sb.AppendLine("<div class=\"sc_title\">");
                        sb.AppendLine(cs.Title);
                        sb.AppendLine("</div>");
                        sb.AppendLine("<div class=\"sc_content\">");
                        sb.AppendLine(cs.Content);
                        sb.AppendLine("</div>");
                        sb.Append("</div>");
                        return sb.ToString();
                    case 1:

                        sb = new StringBuilder();
                        sb.AppendLine("<div class=\"sc\">");
                        sb.AppendLine("<div class=\"sc_title\">");
                        sb.AppendLine(cs.Title);
                        sb.AppendLine("</div>");
                        sb.Append("</div>");
                        return sb.ToString();
                    case 2:

                        sb = new StringBuilder();
                        sb.AppendLine("<div class=\"sc\">");
                        sb.AppendLine("<div class=\"sc_content\">");
                        sb.AppendLine(cs.Content);
                        sb.AppendLine("</div>");
                        sb.Append("</div>");
                        return sb.ToString();
                    default:
                        return this.LabelString;
                }
            }
            catch
            {
                return this.LabelString;
            }
        }
    }
}
